﻿using ConsoleAlgorithms.Tests;
using ConsoleAlgorithms.Utils;
using HelloWorld.Utils;

namespace ConsoleAlgorithms
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //RunTest(new C01_SinProblem());
            //RunTest(new Fraction());
            // RunTest(new EX101_TaylorForSin());
            // RunTest(new EX102_Permutation_Combination());
            //foreach (var n in Numbers.GetCommonDividers(12))
            //    Console.WriteLine(n);

            //RunTest(new C07_MatchSchedule());

            //RunTest(new BigInteger());
            //RunTest(new BigNumber1());
            //RunTest(new BigNumber2());

            // RunTest(new Experiments());
            // RunTest(new C07_DynamicProgramming());

            //Console.WriteLine(MemoryClear()[3][5]);

            //RunTest(new L11_BackTracking());
            RunTest(new BackTrackPermutation());
        }


        public static void RunTest(ITestable testable)
        {
            string className = testable.GetType().FullName + "";
            string space = new string('-', 40 - className.Length / 2);
            Console.WriteLine($"{space} {className} {space}");
            var t1 = DateTime.Now;
            testable.Test();
            var t2 = DateTime.Now;
            Console.WriteLine($"Test time: {(t2 - t1).TotalMilliseconds:N0}ms.\n");
        }


        /// <summary>
        /// 用于清理内容，每秒增加1GB内存空间，直到溢出。
        /// </summary>
        /// <returns></returns>
        public static List<int[]> MemoryClear()
        {
            List<int[]> ars = new List<int[]>();
            try
            {
                while (ars.Count < 10000)
                {
                    int[] array = new int[100 * 1024 * 1024];
                    ars.Add(array);
                    Thread.Sleep(10);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return ars;
        }
    }
}